home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / xdr_rec.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  17KB  |  603 lines

  1. /*
  2.  * $Id: xdr_rec.c,v 1.2 1993/11/14 16:53:55 jraja Exp $
  3.  *
  4.  * $Log: xdr_rec.c,v $
  5.  * Revision 1.2  1993/11/14  16:53:55  jraja
  6.  * Fixed includes, some types, added ANSI prototypes.
  7.  * AMITCP: Added error message to xdrrec_getpos(), since it had an obvious
  8.  * bug: tried to call lseek() on opaque tcp_handle.
  9.  *
  10.  */
  11. /* @(#)xdr_rec.c    2.2 88/08/01 4.0 RPCSRC */
  12. /*
  13.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  14.  * unrestricted use provided that this legend is included on all tape
  15.  * media and as a part of the software program in whole or part.  Users
  16.  * may copy or modify Sun RPC without charge, but are not authorized
  17.  * to license or distribute it to anyone else except as part of a product or
  18.  * program developed by the user.
  19.  * 
  20.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  21.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  22.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  23.  * 
  24.  * Sun RPC is provided with no support and without any obligation on the
  25.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  26.  * modification or enhancement.
  27.  * 
  28.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  29.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  30.  * OR ANY PART THEREOF.
  31.  * 
  32.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  33.  * or profits or other special, indirect and consequential damages, even if
  34.  * Sun has been advised of the possibility of such damages.
  35.  * 
  36.  * Sun Microsystems, Inc.
  37.  * 2550 Garcia Avenue
  38.  * Mountain View, California  94043
  39.  */
  40. #if !defined(lint) && defined(SCCSIDS)
  41. static char sccsid[] = "@(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";
  42. #endif
  43.  
  44. /*
  45.  * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
  46.  * layer above tcp (for rpc's use).
  47.  *
  48.  * Copyright (C) 1984, Sun Microsystems, Inc.
  49.  *
  50.  * These routines interface XDRSTREAMS to a tcp/ip connection.
  51.  * There is a record marking layer between the xdr stream
  52.  * and the tcp transport level.  A record is composed on one or more
  53.  * record fragments.  A record fragment is a thirty-two bit header followed
  54.  * by n bytes of data, where n is contained in the header.  The header
  55.  * is represented as a htonl(u_long).  Thegh order bit encodes
  56.  * whether or not the fragment is the last fragment of the record
  57.  * (1 => fragment is last, 0 => more fragments to follow. 
  58.  * The other 31 bits encode the byte length of the fragment.
  59.  */
  60.  
  61. #include <sys/param.h>
  62. #include <stdio.h>
  63. #include <rpc/types.h>
  64. #include <rpc/xdr.h>
  65. #include <netinet/in.h>
  66.  
  67. static bool_t    xdrrec_getlong(XDR * xdrs, long * lp);
  68. static bool_t    xdrrec_putlong(XDR * xdrs, long * lp);
  69. static bool_t    xdrrec_getbytes(XDR * xdrs, caddr_t addr, u_int len);
  70. static bool_t    xdrrec_putbytes(XDR * xdrs, caddr_t addr, u_int len);
  71. static u_int    xdrrec_getpos(XDR * xdrs);
  72. static bool_t    xdrrec_setpos(XDR * xdrs, u_int pos);
  73. static long *    xdrrec_inline(XDR * xdrs, u_int len);
  74. static void    xdrrec_destroy(XDR * xdrs);
  75.  
  76. static struct  xdr_ops xdrrec_ops = {
  77.     xdrrec_getlong,
  78.     xdrrec_putlong,
  79.     xdrrec_getbytes,
  80.     xdrrec_putbytes,
  81.     xdrrec_getpos,
  82.     xdrrec_setpos,
  83.     xdrrec_inline,
  84.     xdrrec_destroy
  85. };
  86.  
  87. /*
  88.  * A record is composed of one or more record fragments.
  89.  * A record fragment is a two-byte header followed by zero to
  90.  * 2**32-1 bytes.  The header is treated as a long unsigned and is
  91.  * encode/decoded to the network via htonl/ntohl.  The low order 31 bits
  92.  * are a byte count of the fragment.  The highest order bit is a boolean:
  93.  * 1 => this fragment is the last fragment of the record,
  94.  * 0 => this fragment is followed by more fragment(s).
  95.  *
  96.  * The fragment/record machinery is not general;  it is constructed to
  97.  * meet the needs of xdr and rpc based on tcp.
  98.  */
  99.  
  100. #define LAST_FRAG ((u_long)(1 << 31))
  101.  
  102. typedef struct rec_strm {
  103.     void *  tcp_handle;
  104.     caddr_t the_buffer;
  105.     /*
  106.      * out-goung bits
  107.      */
  108.     int (*writeit)(void *, caddr_t, int);
  109.     caddr_t out_base;    /* output buffer (points to frag header) */
  110.     caddr_t out_finger;    /* next output position */
  111.     caddr_t out_boundry;    /* data cannot up to this address */
  112.     u_long *frag_header;    /* beginning of curren fragment */
  113.     bool_t frag_sent;    /* true if buffer sent in middle of record */
  114.     /*
  115.      * in-coming bits
  116.      */
  117.     int (*readit)(void *, caddr_t, int);
  118.     u_long in_size;    /* fixed size of the input buffer */
  119.     caddr_t in_base;
  120.     caddr_t in_finger;    /* location of next byte to be had */
  121.     caddr_t in_boundry;    /* can read up to this location */
  122.     long fbtbc;        /* fragment bytes to be consumed */
  123.     bool_t last_frag;
  124.     u_int sendsize;
  125.     u_int recvsize;
  126. } RECSTREAM;
  127.  
  128. static bool_t flush_out(RECSTREAM * rstrm, int eor);
  129. static bool_t fill_input_buf(RECSTREAM * rstrm);
  130. static bool_t get_input_bytes(RECSTREAM * rstrm, caddr_t addr, int len);
  131. static bool_t set_input_fragment(RECSTREAM * rstrm);
  132. static bool_t skip_input_bytes(RECSTREAM * rstrm, long cnt);
  133. static u_int  fix_buf_size(u_int s);
  134.  
  135. /*
  136.  * Create an xdr handle for xdrrec
  137.  * xdrrec_create fills in xdrs.  Sendsize and recvsize are
  138.  * send and recv buffer sizes (0 => use default).
  139.  * tcp_handle is an opaque handle that is passed as the first parameter to
  140.  * the procedures readit and writeit.  Readit and writeit are read and
  141.  * write respectively.   They are like the system
  142.  * calls expect that they take an opaque handle rather than an fd.
  143.  */
  144. void
  145. xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
  146.     register XDR *xdrs;
  147.     register u_int sendsize;
  148.     register u_int recvsize;
  149.     void * tcp_handle;
  150.     int (*readit)(void *, caddr_t, int);  /* like read, but pass it a tcp_handle, not sock */
  151.     int (*writeit)(void *, caddr_t, int);  /* like write, but pass it a tcp_handle, not sock */
  152. {
  153.     register RECSTREAM *rstrm =
  154.         (RECSTREAM *)mem_alloc(sizeof(RECSTREAM));
  155.  
  156.     if (rstrm == NULL) {
  157.         (void)fprintf(stderr, "xdrrec_create: out of memory\n");
  158.         /* 
  159.          *  This is bad.  Should rework xdrrec_create to 
  160.          *  return a handle, and in this case return NULL
  161.          */
  162.         return;
  163.     }
  164.     /*
  165.      * adjust sizes and allocate buffer quad byte aligned
  166.      */
  167.     rstrm->sendsize = sendsize = fix_buf_size(sendsize);
  168.     rstrm->recvsize = recvsize = fix_buf_size(recvsize);
  169.     rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
  170.     if (rstrm->the_buffer == NULL) {
  171.         (void)fprintf(stderr, "xdrrec_create: out of memory\n");
  172.         return;
  173.     }
  174.     for (rstrm->out_base = rstrm->the_buffer;
  175.         (u_int)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
  176.         rstrm->out_base++);
  177.     rstrm->in_base = rstrm->out_base + sendsize;
  178.     /*
  179.      * now the rest ...
  180.      */
  181.     xdrs->x_ops = &xdrrec_ops;
  182.     xdrs->x_private = (caddr_t)rstrm;
  183.     rstrm->tcp_handle = tcp_handle;
  184.     rstrm->readit = readit;
  185.     rstrm->writeit = writeit;
  186.     rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
  187.     rstrm->frag_header = (u_long *)rstrm->out_base;
  188.     rstrm->out_finger += sizeof(u_long);
  189.     rstrm->out_boundry += sendsize;
  190.     rstrm->frag_sent = FALSE;
  191.     rstrm->in_size = recvsize;
  192.     rstrm->in_boundry = rstrm->in_base;
  193.     rstrm->in_finger = (rstrm->in_boundry += recvsize);
  194.     rstrm->fbtbc = 0;
  195.     rstrm->last_frag = TRUE;
  196. }
  197.  
  198.  
  199. /*
  200.  * The reoutines defined below are the xdr ops which will go into the
  201.  * xdr handle filled in by xdrrec_create.
  202.  */
  203.  
  204. static bool_t
  205. xdrrec_getlong(xdrs, lp)
  206.     XDR *xdrs;
  207.     long *lp;
  208. {
  209.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  210.     register long *buflp = (long *)(rstrm->in_finger);
  211.     long mylong;
  212.  
  213.     /* first try the inline, fast case */
  214.     if ((rstrm->fbtbc >= sizeof(long)) &&
  215.         (((int)rstrm->in_boundry - (int)buflp) >= sizeof(long))) {
  216.         *lp = (long)ntohl((u_long)(*buflp));
  217.         rstrm->fbtbc -= sizeof(long);
  218.         rstrm->in_finger += sizeof(long);
  219.     } else {
  220.         if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(long)))
  221.             return (FALSE);
  222.         *lp = (long)ntohl((u_long)mylong);
  223.     }
  224.     return (TRUE);
  225. }
  226.  
  227. static bool_t
  228. xdrrec_putlong(xdrs, lp)
  229.     XDR *xdrs;
  230.     long *lp;
  231. {
  232.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  233.     register long *dest_lp = ((long *)(rstrm->out_finger));
  234.  
  235.     if ((rstrm->out_finger += sizeof(long)) > rstrm->out_boundry) {
  236.         /*
  237.          * this case should almost never happen so the code is
  238.          * inefficient
  239.          */
  240.         rstrm->out_finger -= sizeof(long);
  241.         rstrm->frag_sent = TRUE;
  242.         if (! flush_out(rstrm, FALSE))
  243.             return (FALSE);
  244.         dest_lp = ((long *)(rstrm->out_finger));
  245.         rstrm->out_finger += sizeof(long);
  246.     }
  247.     *dest_lp = (long)htonl((u_long)(*lp));
  248.     return (TRUE);
  249. }
  250.  
  251. static bool_t  /* must manage buffers, fragments, and records */
  252. xdrrec_getbytes(xdrs, addr, len)
  253.     XDR *xdrs;
  254.     register caddr_t addr;
  255.     register u_int len;
  256. {
  257.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  258.     register int current;
  259.  
  260.     while (len > 0) {
  261.         current = rstrm->fbtbc;
  262.         if (current == 0) {
  263.             if (rstrm->last_frag)
  264.                 return (FALSE);
  265.             if (! set_input_fragment(rstrm))
  266.                 return (FALSE);
  267.             continue;
  268.         }
  269.         current = (len < current) ? len : current;
  270.         if (! get_input_bytes(rstrm, addr, current))
  271.             return (FALSE);
  272.         addr += current; 
  273.         rstrm->fbtbc -= current;
  274.         len -= current;
  275.     }
  276.     return (TRUE);
  277. }
  278.  
  279. static bool_t
  280. xdrrec_putbytes(xdrs, addr, len)
  281.     XDR *xdrs;
  282.     register caddr_t addr;
  283.     register u_int len;
  284. {
  285.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  286.     register int current;
  287.  
  288.     while (len > 0) {
  289.         current = (u_int)rstrm->out_boundry - (u_int)rstrm->out_finger;
  290.         current = (len < current) ? len : current;
  291.         bcopy(addr, rstrm->out_finger, current);
  292.         rstrm->out_finger += current;
  293.         addr += current;
  294.         len -= current;
  295.         if (rstrm->out_finger == rstrm->out_boundry) {
  296.             rstrm->frag_sent = TRUE;
  297.             if (! flush_out(rstrm, FALSE))
  298.                 return (FALSE);
  299.         }
  300.     }
  301.     return (TRUE);
  302. }
  303.  
  304. static u_int
  305. xdrrec_getpos(xdrs)
  306.     register XDR *xdrs;
  307. {
  308.     register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
  309.     register long pos;
  310. #ifdef AMITCP
  311.     /*
  312.      * Calling lseek() on a opaque tcp_handle is doomed to fail. In 
  313.      * addition, lseek cannot be performed on a socket, so why 
  314.      * bother to call the lseek() at all?
  315.      */
  316.     pos = -1;
  317.     fprintf(stderr, "xdr_rec.c: someone called xdrrec_getpos()!");
  318. #else
  319.     pos = lseek((int)rstrm->tcp_handle, (long) 0, 1);
  320. #endif
  321.     if (pos != -1)
  322.         switch (xdrs->x_op) {
  323.  
  324.         case XDR_ENCODE:
  325.             pos += rstrm->out_finger - rstrm->out_base;
  326.             break;
  327.  
  328.         case XDR_DECODE:
  329.             pos -= rstrm->in_boundry - rstrm->in_finger;
  330.             break;
  331.  
  332.         default:
  333.             pos = (u_int) -1;
  334.             break;
  335.         }
  336.     return ((u_int) pos);
  337. }
  338.  
  339. static bool_t
  340. xdrrec_setpos(xdrs, pos)
  341.     register XDR *xdrs;
  342.     u_int pos;
  343. {
  344.     register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
  345.     u_int currpos = xdrrec_getpos(xdrs);
  346.     int delta = currpos - pos;
  347.     caddr_t newpos;
  348.  
  349.     if ((int)currpos != -1)
  350.         switch (xdrs->x_op) {
  351.  
  352.         case XDR_ENCODE:
  353.             newpos = rstrm->out_finger - delta;
  354.             if ((newpos > (caddr_t)(rstrm->frag_header)) &&
  355.                 (newpos < rstrm->out_boundry)) {
  356.                 rstrm->out_finger = newpos;
  357.                 return (TRUE);
  358.             }
  359.             break;
  360.  
  361.         case XDR_DECODE:
  362.             newpos = rstrm->in_finger - delta;
  363.             if ((delta < (int)(rstrm->fbtbc)) &&
  364.                 (newpos <= rstrm->in_boundry) &&
  365.                 (newpos >= rstrm->in_base)) {
  366.                 rstrm->in_finger = newpos;
  367.                 rstrm->fbtbc -= delta;
  368.                 return (TRUE);
  369.             }
  370.             break;
  371.         }
  372.     return (FALSE);
  373. }
  374.  
  375. static long *
  376. xdrrec_inline(xdrs, len)
  377.     register XDR *xdrs;
  378.     u_int len;
  379. {
  380.     register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
  381.     long * buf = NULL;
  382.  
  383.     switch (xdrs->x_op) {
  384.  
  385.     case XDR_ENCODE:
  386.         if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
  387.             buf = (long *) rstrm->out_finger;
  388.             rstrm->out_finger += len;
  389.         }
  390.         break;
  391.  
  392.     case XDR_DECODE:
  393.         if ((len <= rstrm->fbtbc) &&
  394.             ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
  395.             buf = (long *) rstrm->in_finger;
  396.             rstrm->fbtbc -= len;
  397.             rstrm->in_finger += len;
  398.         }
  399.         break;
  400.     }
  401.     return (buf);
  402. }
  403.  
  404. static void
  405. xdrrec_destroy(xdrs)
  406.     register XDR *xdrs;
  407. {
  408.     register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
  409.  
  410.     mem_free(rstrm->the_buffer,
  411.         rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
  412.     mem_free((caddr_t)rstrm, sizeof(RECSTREAM));
  413. }
  414.  
  415.  
  416. /*
  417.  * Exported routines to manage xdr records
  418.  */
  419.  
  420. /*
  421.  * Before reading (deserializing from the stream, one should always call
  422.  * this procedure to guarantee proper record alignment.
  423.  */
  424. bool_t
  425. xdrrec_skiprecord(xdrs)
  426.     XDR *xdrs;
  427. {
  428.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  429.  
  430.     while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
  431.         if (! skip_input_bytes(rstrm, rstrm->fbtbc))
  432.             return (FALSE);
  433.         rstrm->fbtbc = 0;
  434.         if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
  435.             return (FALSE);
  436.     }
  437.     rstrm->last_frag = FALSE;
  438.     return (TRUE);
  439. }
  440.  
  441. /*
  442.  * Look ahead fuction.
  443.  * Returns TRUE iff there is no more input in the buffer 
  444.  * after consuming the rest of the current record.
  445.  */
  446. bool_t
  447. xdrrec_eof(xdrs)
  448.     XDR *xdrs;
  449. {
  450.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  451.  
  452.     while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
  453.         if (! skip_input_bytes(rstrm, rstrm->fbtbc))
  454.             return (TRUE);
  455.         rstrm->fbtbc = 0;
  456.         if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
  457.             return (TRUE);
  458.     }
  459.     if (rstrm->in_finger == rstrm->in_boundry)
  460.         return (TRUE);
  461.     return (FALSE);
  462. }
  463.  
  464. /*
  465.  * The client must tell the package when an end-of-record has occurred.
  466.  * The second paraemters tells whether the record should be flushed to the
  467.  * (output) tcp stream.  (This let's the package support batched or
  468.  * pipelined procedure calls.)  TRUE => immmediate flush to tcp connection.
  469.  */
  470. bool_t
  471. xdrrec_endofrecord(xdrs, sendnow)
  472.     XDR *xdrs;
  473.     bool_t sendnow;
  474. {
  475.     register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
  476.     register u_long len;  /* fragment length */
  477.  
  478.     if (sendnow || rstrm->frag_sent ||
  479.         ((u_long)rstrm->out_finger + sizeof(u_long) >=
  480.         (u_long)rstrm->out_boundry)) {
  481.         rstrm->frag_sent = FALSE;
  482.         return (flush_out(rstrm, TRUE));
  483.     }
  484.     len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->frag_header) -
  485.        sizeof(u_long);
  486.     *(rstrm->frag_header) = htonl((u_long)len | LAST_FRAG);
  487.     rstrm->frag_header = (u_long *)rstrm->out_finger;
  488.     rstrm->out_finger += sizeof(u_long);
  489.     return (TRUE);
  490. }
  491.  
  492.  
  493. /*
  494.  * Internal useful routines
  495.  */
  496. static bool_t
  497. flush_out(rstrm, eor)
  498.     register RECSTREAM *rstrm;
  499.     bool_t eor;
  500. {
  501.     register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
  502.     register u_long len = (u_long)(rstrm->out_finger) - 
  503.         (u_long)(rstrm->frag_header) - sizeof(u_long);
  504.  
  505.     *(rstrm->frag_header) = htonl(len | eormask);
  506.     len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->out_base);
  507.     if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
  508.         != (int)len)
  509.         return (FALSE);
  510.     rstrm->frag_header = (u_long *)rstrm->out_base;
  511.     rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_long);
  512.     return (TRUE);
  513. }
  514.  
  515. static bool_t  /* knows nothing about records!  Only about input buffers */
  516. fill_input_buf(rstrm)
  517.     register RECSTREAM *rstrm;
  518. {
  519.     register caddr_t where;
  520.     u_int i;
  521.     register int len;
  522.  
  523.     where = rstrm->in_base;
  524.     i = (u_int)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
  525.     where += i;
  526.     len = rstrm->in_size - i;
  527.     if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
  528.         return (FALSE);
  529.     rstrm->in_finger = where;
  530.     where += len;
  531.     rstrm->in_boundry = where;
  532.     return (TRUE);
  533. }
  534.  
  535. static bool_t  /* knows nothing about records!  Only about input buffers */
  536. get_input_bytes(rstrm, addr, len)
  537.     register RECSTREAM *rstrm;
  538.     register caddr_t addr;
  539.     register int len;
  540. {
  541.     register int current;
  542.  
  543.     while (len > 0) {
  544.         current = (int)rstrm->in_boundry - (int)rstrm->in_finger;
  545.         if (current == 0) {
  546.             if (! fill_input_buf(rstrm))
  547.                 return (FALSE);
  548.             continue;
  549.         }
  550.         current = (len < current) ? len : current;
  551.         bcopy(rstrm->in_finger, addr, current);
  552.         rstrm->in_finger += current;
  553.         addr += current;
  554.         len -= current;
  555.     }
  556.     return (TRUE);
  557. }
  558.  
  559. static bool_t  /* next two bytes of the input stream are treated as a header */
  560. set_input_fragment(rstrm)
  561.     register RECSTREAM *rstrm;
  562. {
  563.     u_long header;
  564.  
  565.     if (! get_input_bytes(rstrm, (caddr_t)&header, sizeof(header)))
  566.         return (FALSE);
  567.     header = (long)ntohl(header);
  568.     rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
  569.     rstrm->fbtbc = header & (~LAST_FRAG);
  570.     return (TRUE);
  571. }
  572.  
  573. static bool_t  /* consumes input bytes; knows nothing about records! */
  574. skip_input_bytes(rstrm, cnt)
  575.     register RECSTREAM *rstrm;
  576.     long cnt;
  577. {
  578.     register int current;
  579.  
  580.     while (cnt > 0) {
  581.         current = (int)rstrm->in_boundry - (int)rstrm->in_finger;
  582.         if (current == 0) {
  583.             if (! fill_input_buf(rstrm))
  584.                 return (FALSE);
  585.             continue;
  586.         }
  587.         current = (cnt < current) ? cnt : current;
  588.         rstrm->in_finger += current;
  589.         cnt -= current;
  590.     }
  591.     return (TRUE);
  592. }
  593.  
  594. static u_int
  595. fix_buf_size(s)
  596.     register u_int s;
  597. {
  598.  
  599.     if (s < 100)
  600.         s = 4000;
  601.     return (RNDUP(s));
  602. }
  603.